<template>
	<view class="index-content">
		<view class="info-content">
			<view class="content-top" @click="handleDetail(item)" v-for="(item, index) in allLabel" :key="index">
				<view class="content-top-title">{{item.taskNo}}</view>
				<view class="content-top-title-middle">
					<view class="content-top-title-middle-left">{{item.materalName}}</view>
					<view>
						<u-tag text="绑  定" type="success" shape="circle" color="#5AC0BE" bg-color="#EEF8F8"
							border-color="#EEF8F8" v-if="item.bizType == '10'" />
						<u-tag text="解  绑" type="success" shape="circle" color="#F1A35F" bg-color="#FDF5EF"
							border-color="#FDF5EF" v-if="item.bizType == '20'" />
						<u-tag text="调整标签" type="success" shape="circle" color="#4899F3" bg-color="#ECF4FD"
							border-color="#ECF4FD" v-if="item.bizType == '30'" />
						<u-tag text="调整标签组" type="success" shape="circle" color="#1F4DBB" bg-color="#E8EDF8"
							border-color="#E8EDF8" v-if="item.bizType == '40'" />
					</view>
				</view>
				<view class="content-top-title-info">
					<view class="content-top-title-text" style="width: 60%;">数量：{{item.qty}}</view>
					<view class="content-top-title-text">重量：{{item.wgt}}</view>
				</view>
				<view class="content-bottom-title">客户 {{item.custormerName}}</view>
			</view>
			<view class="load-more" v-if="allLabel && allLabel.length > 0">
				<u-loading class="loading" :mode="flower" size="32rpx" text-size="24rpx" v-if="loadType === 'load'">
					加载中...
				</u-loading>
				<view class="no-more" v-else="loadType === 'nomore'">已经到底啦~</view>
			</view>
			<view class="no-data" v-else>暂无数据~</view>
		</view>
	</view>
</template>

<script>
	import {
		getAllTasks,
		taskStart
	} from '@/api/index.js';
	const myDate = new Date();
	const year = myDate.getFullYear(); // 获取当前年份
	const month = myDate.getMonth() + 1; // 获取当前月份(0-11,0代表1月所以要加1);
	const day = myDate.getDate(); // 获取当前日（1-31）
	export default {
		data() {
			return {
				//屏幕高度
				screenHeight: 0,
				date: `${year}-${month}-${day}`,
				current: 0,
				page: 1,
				pageSize: 10,
				loadType: '', // 分页加载状况  load：加载中；  nomore：没有更多
				flower: 'flower',
				allLabel: []
			}
		},
		onLoad() {
			this.screenHeight = uni.getSystemInfoSync().windowHeight;
		},
		onShow() {
			this.getData();
		},
		//上拉加载更多
		onReachBottom() {
			if (this.loadType === 'nomore') return;
			this.page = this.page + 1;
			this.getData();
		},
		onPullDownRefresh() {
			this.page = 1;
			this.getData();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		methods: {
			handleDetail(data) {
				if (data.bizType == "10") {
					uni.navigateTo({
						url: "/pages/tabbar/labelAdjustmentDetail/labelAdjustmentDetail?data=" + JSON
							.stringify(data)
					})
				} else {
					// 开始任务
					taskStart({
						tagGroupNo: data.orgGroupNo,
						userName: uni.getStorageSync('userName')
					}).then((res) => {
						if (res && res.state == "ok") {
							uni.navigateTo({
								url: "/pages/tabbar/labelAdjustmentDetail/labelAdjustmentDetail?data=" +
									JSON
									.stringify(data)
							})
						} else if (res && res.state == "fail") {
							uni.showToast({
								title: res.msg,
								icon: 'none',
								duration: 3000
							})
						}
					})
				}
			},
			getData() {
				let page = this.page;
				let allLabel = [];
				let loadType = 'load';
				// 显示loading状态
				uni.showLoading({
					mark: true,
					title: "加载中..."
				})
				let params = {
					date: this.date,
					// account: uni.getStorageSync('account'),
					pageNumber: this.page,
					pageSize: this.pageSize,
				}
				getAllTasks(params).then((res) => {
					if (res && res.state == "ok") {
						uni.hideLoading()
						// 获取列表数据
						if (this.page === 1) {
							allLabel = res.data.row || []
						} else {
							allLabel = this.allLabel.concat(res.data.data)
						}
						// 设置加载状态
						if (parseInt(res.data.totalRow) <= this.page * this.pageSize) loadType = 'nomore'
						this.allLabel = allLabel;
						this.loadType = loadType;
					} else if (res && res.state == "fail") {
						uni.hideLoading();
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 3000
						})
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #EEF0F4;
		font-size: 18px;
	}

	.index-content {
		width: 100%;
		height: 200px;
		background-image: linear-gradient(180deg, #4899F3 0%, rgba(72, 153, 243, 0.00) 100%);
	}

	.info-content {
		padding: 10px;
	}

	.content-top {
		width: 100%;
		height: auto;
		background: #FFFFFF;
		border-radius: 4px;
		padding: 10px;
		margin-bottom: 10px;
	}

	.content-top-title {
		font-size: 12px;
		color: rgba(23, 26, 29, 0.40);
		line-height: 18px;
	}

	.content-top-title-middle {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 5px 0;
	}

	.content-top-title-middle-left {
		font-weight: bold;
		font-size: 16px;
		color: #171A1D;
	}

	.content-top-title-info {
		display: flex;
		justify-content: flex-start;
		align-items: center;
		padding: 8px 0;
		border-bottom: 1px solid #EEF0F4;
	}

	.content-top-title-text {
		font-weight: bold;
		font-size: 14px;
		color: rgba(23, 26, 29, 0.60);
	}

	.content-bottom-title {
		font-size: 12px;
		color: rgba(23, 26, 29, 0.40);
		line-height: 24px;
		padding-top: 12px;
	}

	.u-shape-circle {
		width: 90px;
		text-align: center;
	}

	.load-more {
		display: flex;
		justify-content: center;
		align-items: center;
		margin-top: 12rpx;
		height: 80rpx;
	}

	.load-more .van-loading__text {
		color: #c9c9c9;
	}

	.load-more .no-more {
		font-size: 20px;
		color: #c9c9c9;
	}

	.no-data {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		font-size: 20px;
		color: #c9c9c9;
		margin-top: 120px !important;
	}
</style>
